import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

import 'package:get/get.dart';
import 'package:zrjz/comm/constants/constants.dart';

import '../../constants/color_constants.dart';

class DatePickerUtil {
  static void showCupertinoDatePicker({
    required Function(DateTime) onDateTimeChanged,
    DateTime? initialDateTime,
    int minimumYear = 1970,
    int maximumYear = 9999,
    int minuteInterval = 1,
    DateTime? minimumDate,
    DateTime? maximumDate,
    CupertinoDatePickerMode mode = CupertinoDatePickerMode.date,
    String title = '',
    DatePickerDateOrder? dateOrder,
  }) {
    initialDateTime ??= DateTime.now();
    minimumDate ??= DateTime(1970, 1, 1);
    maximumDate ??= DateTime(9999, 12, 31);

    SmartDialog.show(
      usePenetrate: false,
      tag: 'date_picker',
      maskColor: Colors.black.withOpacity(0.4),
      alignment: Alignment.bottomCenter,
      builder: (BuildContext context) {
        return Container(
          height: 280,
          decoration: BoxDecoration(
            color: DarkThemeUtil.multiColors(ColorConstants.white, darkColor: ColorConstants.darkBlackItem),
            borderRadius: const BorderRadius.only(topLeft: Radius.circular(25), topRight: Radius.circular(25)),
          ),
          child: Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  CupertinoButton(
                    child: Text(
                      '取消'.tr,
                      style: const TextStyle(
                        fontSize: 17,
                        fontWeight: FontWeight.w500,
                        color: ColorConstants.appBlue,
                      ),
                    ),
                    onPressed: () => SmartDialog.dismiss(tag: 'date_picker'),
                  ),
                  Text(
                    title.tr,
                    style: TextStyle(
                      fontSize: 18,
                      fontWeight: FontWeight.w500,
                      color: DarkThemeUtil.multiColors(ColorConstants.black404A5B, darkColor: ColorConstants.white),
                    ),
                  ),
                  CupertinoButton(
                    child: Text(
                      '确认'.tr,
                      style: const TextStyle(
                        fontSize: 17,
                        fontWeight: FontWeight.w500,
                        color: ColorConstants.appBlue,
                      ),
                    ),
                    onPressed: () {
                      SmartDialog.dismiss(tag: 'date_picker');
                      // 将选中的值通过回调函数传递出去
                      onDateTimeChanged(initialDateTime!);
                    },
                  ),
                ],
              ),
              Divider(
                  color: DarkThemeUtil.multiColors(
                    ColorConstants.dividerD9,
                    darkColor: ColorConstants.darkBlackItemDivider,
                  ),
                  height: 0.5),
              Expanded(
                child: CupertinoDatePicker(
                  mode: mode,
                  use24hFormat: true,
                  initialDateTime: initialDateTime,
                  onDateTimeChanged: (date) {
                    initialDateTime = date;
                  },
                  dateOrder: dateOrder,
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
